package com.usian.controller;

import com.github.pagehelper.PageInfo;
import com.usian.pojo.Department;
import com.usian.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static tk.mybatis.mapper.entity.Config.PREFIX;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;


    @RequestMapping("/findAll")
    public PageInfo<Department> findAll(Integer page, Integer size, @RequestBody Department department){
        if (null == page){
            page = 1;
        }
        if (null == size){
            size = 2;
        }
        return departmentService.findAll(page,size,department);
    }


    /**
     * 登陆页
     * @return
     */
    @GetMapping("/userlogin")
    public String loginPage() {
        return PREFIX+"login";
    }

    @RequestMapping("/add")
    public void add(@RequestBody Department department){
        departmentService.add(department);
    }

    @RequestMapping("/etid")
    public void etid(@RequestBody Department department){
        departmentService.etid(department);
    }

    @RequestMapping("/del")
    public void del(Integer id){
        departmentService.del(id);
    }

}
